from django.contrib.gis import admin

from common.base_admin import BaseGisAdmin, BaseTabularInline
from .models import ScenicAreaType, ScenicArea, ScenicAreaMap, \
    Track, RoadType, Road, IconLegend, BackgroundMusic, Multimap, CronTask
from common.base_admin_site import admin_site

class IconLegendAdmin(BaseGisAdmin):
    list_display = ('id', 'name', 'icon_width', 'icon_height')
    list_editable = ('icon_width', 'icon_height')

class ScenicAreaTypeAdmin(BaseGisAdmin):
    list_display = ('id', 'name', 'show', 'orderid')
    list_editable = ('show', 'orderid')


class ScenicAreaAdmin(BaseGisAdmin):
    list_display = ( 'mname', 'text2speech', 'has_audio_file', 'show_footer', 'footer_position', 'footer_width', 'legend', 'scenic_area_type', 'scenic_area', 'root', 'operate')
    list_editable = ('show_footer', 'footer_position', 'footer_width', 'legend', 'scenic_area_type', 'scenic_area')
    filter_horizontal = ('children_scenic_area_type',)
    search_fields = ('name', 'scenic_area__name',)
    autocomplete_fields =('scenic_area',)

class ScenicAreaMapAdmin(BaseGisAdmin):
    list_display = ('mname', 'gdal2tiles', 'zoom', 'min_zoom', 'max_zoom', 'scenic_area')
    list_editable = ('zoom', 'min_zoom', 'max_zoom', 'scenic_area')
    autocomplete_fields =('scenic_area',)

class TrackAdmin(BaseGisAdmin):
    autocomplete_fields =('scenic_area',)

class RoadTypeAdmin(BaseGisAdmin):
    list_display = ('mname', 'orderid')
    list_editable = ['orderid']
    autocomplete_fields =('scenic_area',)

class ScenicInlineAdmin(BaseTabularInline):
    model = Road.related_scenics.through
    verbose_name = '路线上的景区'
    verbose_name_plural = '路线上的景区'
    list_display = ['scenic','orderid']
    autocomplete_fields =('scenic',)

class RoadAdmin(BaseGisAdmin):
    inlines = (ScenicInlineAdmin,)

    list_display = ('mname', 'orderid')
    filter_horizontal = ('related_scenics',)
    list_editable = ['orderid']
    autocomplete_fields =('scenic_area',)

class RoadScenicsAdmin(BaseGisAdmin):
    list_display = ['road','scenic','orderid']
    list_editable = ['orderid']
    autocomplete_fields =('scenic_area',)

class BackgroundMusicAdmin(BaseGisAdmin):
    list_display = ['name','default', 'modify_db']
    list_editable = ['default', 'modify_db']

class MultimapAdmin(BaseGisAdmin):
    list_display = ['name', 'icon_width', 'icon_height', 'scenic_area', 'orderid']
    list_editable = ['icon_width', 'icon_height', 'orderid']
    autocomplete_fields =('scenic_area',)

class CronTaskAdmin(BaseGisAdmin):
    list_display = ('scenic_area', 'parent_scenic', 'using', 'task_type', 'operate')
    list_editable = ('parent_scenic', 'using', 'task_type')
    autocomplete_fields =('scenic_area', 'parent_scenic')


# from .models import ScenicArea, TourRoute, \
#     ScenicSpot, Restaurant, Toilet, BabyRoom, WaterFountain, Track, TrafficPoint
admin_site.register(IconLegend, IconLegendAdmin)
admin_site.register(ScenicAreaType, ScenicAreaTypeAdmin)
admin_site.register(ScenicArea, ScenicAreaAdmin)
admin_site.register(ScenicAreaMap, ScenicAreaMapAdmin)
admin_site.register(Track, TrackAdmin)
admin_site.register(RoadType, RoadTypeAdmin)
admin_site.register(Road, RoadAdmin)
admin_site.register(BackgroundMusic, BackgroundMusicAdmin)
admin_site.register(Multimap, MultimapAdmin)
admin_site.register(CronTask, CronTaskAdmin)